<template>
	<view class="order">
		<!-- <view class="backColor-styless" :style="{ 'background-image' :  backColor }"></view> -->
		<view style="position: relative;width: 100%;">
			<view class="u-notice-bar-styless">
				<u-notice-bar mode="horizontal" border-radius="16" type="error" :list="list"></u-notice-bar>
			</view>
			<view class="nav" v-if="goodDetail">
				<view class="nav-shopping">
					<view>
						<image :src="goodDetail.image[0].file_path"
							style="width: 160upx;height:160upx;border-radius: 10upx;"></image>
					</view>
					<view style="height: 160upx;padding-left: 24upx;">
						<view><text
								style="font-size: 28upx;font-weight: bold;">{{goodDetail.subtitle_title ? goodDetail.subtitle_title : '暂无商品昵称'}}</text><text
								style="font-size: 24upx;color: #A7ABB6;margin-left: 24upx;"></text></view>
						<view class="demo-price">
							<view
								style="color: rgba(0, 0, 0, 0.35);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;width: 460upx;">
								截止：{{goodDetail.validity_end ? goodDetail.validity_end : ''}}</view>
							<!-- <view><image src="../../static/sds.png" style="width: 25upx;height: 25upx;"></image></view> -->
							<!-- <view>￥{{(goodDetail.price / goodDetail.selectNumQs).toFixed(2)}} / 月</view> -->
						</view>
						<view style="margin-top: 20upx;color: rgba(0, 0, 0, 0.35);">
							数量：{{value}}
						</view>
						<!-- <view class="gg-font">蓝色 500ml</view> -->
					</view>
				</view>
				<view class="man-info" style="margin-top: 30upx;">预订人信息</view>
				<view class="nav">
					<u-form label-width="160" :model="userinfo" ref="uForm">
						<u-form-item prop="user_name">
							<u-field v-model="userinfo.user_name" label="使用人:" placeholder="请填写使用人">
							</u-field>
						</u-form-item>
						<u-form-item prop="phone">
							<u-field v-model="userinfo.phone" label="手机号:" placeholder="请填写手机号">
							</u-field>
						</u-form-item>
						<u-form-item prop="pw_personid_type" v-if="couponDetail.need_travel_dates == 1">
							<u-field v-model="userinfo.pw_personid_type" label="身份证:" placeholder="请填写身份证">
							</u-field>
						</u-form-item>
						<u-form-item prop="time" v-if="goodDetail.need_travel_dates == 1">
							<u-field v-model="userinfo.time" :disabled="true" label="出行日期:" placeholder="请填写出行日期"
								@click="showData = true">
							</u-field>
						</u-form-item>
						<u-calendar v-model="showData" :mode="range" @change="changeDate"></u-calendar>
					</u-form>
				</view>

				<view class="man-info" style="margin-top:40upx;">支付方式</view>
				<view class="pay-fs">
					<image src="../../static/wvxpay.svg" style="width: 60upx;height: 50upx;"></image>
					<view>微信支付</view>
				</view>
			</view>
			<view class="footer"></view>
			<view class="bottom-btn">
				<view style="display: flex;justify-content: space-between;width: 100%;align-items: center;">
					<view style="font-size: 25upx;margin-left: 32upx;margin-top: 15upx;">
						<view class="font-24">实付款：
							<span class="font-28" style="color: #F34141;">
								￥{{goodDetail.goods_price ? goodDetail.goods_price : 0}}
							</span>
						</view>
					</view>
					<view class="btn" @click="submit">立即购买</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showData: false,
				show: false,
				content: '企业租赁，需填写完整信息',
				userinfo: {
					user_name: '',
					phone: '',
					pw_personid_type: '',
					time: '',
					pw_playtime: '',
					pw_time_slot: ''
				},
				orderDateilList: {},
				starttime: '',
				endtime: '',
				backColor: {
					background: '#ffffff'
				},
				modeType: null,
				order: {},
				list: ['温馨提示：请确认本次购买是在本人自愿条件下下单'],
				value: 1,
				addressObject: {},
				addressList: [],
				goodDetail: {},
				mobile: '',
				type: '1',
				user_name: '',
				phone: '',
				pw_personid_type: '',
				time: '',
				pw_playtime: '',
				pw_time_slot: '',
				rules: {
					user_name: [{
						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],
					pw_personid_type: [{
						required: true,
						message: '请输入身份证',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],
					phone: [{
						required: true,
						message: '请输入手机号码',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}]
				}
			}
		},
		// 月份加一
		onLoad(e) {},
		onPullDownRefresh() {
			uni.stopPullDownRefresh();
		},
		onShow() {
			this.getDetail()
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			changeDate(e) {
				this.time = e.startDate + '~' + e.endDate
				this.pw_playtime = e.startDate
				this.pw_time_slot = e.endDate
				this.userinfo.time = e.startDate + '~' + e.endDate
				this.userinfo.pw_playtime = e.startDate
				this.userinfo.pw_time_slot = e.endDate
				console.log(e);
			},
			getDetail() {
				this.$request('', '/api/app/coupon/coupondev', 'POST', {
					goods_id: uni.getStorageSync('good_id')
				}, {}).then(res => {
					this.goodDetail = res.data
				})
			},
			// 表单校验
			submit() {
				console.log('111')
				var that = this
				this.$refs.uForm.validate(valid => {
					if (valid) {
						that.creater_order()
					} else {
						console.log('验证失败');
					}
				});
			},
			open() {
				this.show = true;
			},
			confirm() {
				uni.navigateTo({
					url: '/pages/binddriver/index'
				})
			},
			gettime() {
				var date = new Date();
				var seperator1 = "-";
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}
				var currentdate = year + seperator1 + month + seperator1 + strDate;
				this.starttime = currentdate;
				// console.log(this.goodDetail.buy_num)
				this.endtime = this.addMonths(currentdate, this.goodDetail.selectNumQs) + seperator1 + strDate
			},
			addMonths(yearMonthDay, monthNum) {
				var arr = yearMonthDay.split('-'); //2020-08-19或2020-08
				var year = parseInt(arr[0]);
				var month = parseInt(arr[1]);
				month = month + monthNum;
				if (month > 12) { //月份加
					var yearNum = parseInt((month - 1) / 12);
					month = month % 12 == 0 ? 12 : month % 12;
					year += yearNum;
				} else if (month <= 0) { //月份减
					month = Math.abs(month);
					var yearNum = parseInt((month + 12) / 12);
					year -= yearNum;
				}
				month = month < 10 ? "0" + month : month;
				return year + "-" + month;
			},
			// 创建订单
			creater_order() {
				this.$request('', '/api/app/huibendi/getopenapicreateorder', 'POST', {
					goods_id: uni.getStorageSync('good_id'),
					user_name: this.userinfo.user_name,
					phone: this.userinfo.phone,
					goods_num: 1,
					pw_playtime: this.userinfo.pw_playtime,
					pw_time_slot: this.userinfo.pw_time_slot,
					pw_personid_type: this.userinfo.pw_personid_type,
					aid: uni.getStorageSync('aid')
				}, {}).then(res => {
					this.getpay(res.data)
				})
			},
			// 获取支付参数
			getpay(val) {
				var that = this
				this.$request('', '/api/app/coupon/payment', 'POST', {
					openid: uni.getStorageSync('openid'),
					goods_id: uni.getStorageSync('good_id'),
					num: val.order_total_num,
					fee: val.order_total_price,
					order_no: val.order_no
				}, {}).then(responss => {
					console.log(responss.data)
					uni.requestPayment({
						provider: 'wxpay',
						timeStamp: responss.data.timestamp,
						nonceStr: responss.data.nonceStr,
						package: responss.data.package,
						signType: responss.data.signType,
						paySign: responss.data.paySign,
						success: function(res) {
							that.$request('', '/api/app/huibendi/getopenapiorderpay', 'POST', {
								order_no: val.order_no
							}, {}).then(respons => {
								that.$request('', '/api/app/coupon/xcxqueryorder', 'POST', {
									out_trade_no: responss.out_trade_no
								}, {}).then(respons => {
									uni.navigateTo({
										url: '/pages/coupon/index'
									})
								})
								that.$request('', '/api/app/huibendi/getopenapivercodedetail',
									'POST', {
										order_no: val.order_no
									}, {}).then(respons => {

								})
							})
						},
						fail: function(err) {
							console.log('fail:' + JSON.stringify(err));
						}
					});
					// this.$request('', '/api/app/huibendi/getopenapiorderpay', 'POST', {
					// 	order_no: val
					// }, {}).then(respons => {

					// })
				})
			},
			// 获取地址列表
			getaddresslist() {

			},
			getSwitchValue(index) {
				this.type = index.key
			},
			getOpen() {
				this.$refs.child.open()
			},
			editAddress() {
				uni.navigateTo({
					url: '/pages/address/index'
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.pay-fs {
		width: 99%;
		display: flex;
		padding-left: 30upx;
		margin-top: 50upx;
		align-items: center;
		height: 90upx;
		border-bottom: 1upx solid #ECF5FF;
		border-top: 1upx solid #ECF5FF;
		margin: 0 auto;
	}

	.man-info {
		margin-left: 35upx;
		font-weight: bold;
		font-size: 35upx;
	}

	.zj-rl {
		width: 95%;
		background-color: rgb(241, 241, 241);
		border-radius: 50upx;
		height: 100upx;
		margin: 0 auto;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 30upx;
		padding-right: 30upx;
	}

	.u-notice-bar-styless {
		width: 100%;
		background-color: #FFFFFF;
		margin: 0 auto;
		border-radius: 16upx;
	}

	.backColor-styless {
		position: absolute;
		width: 100%;
		height: 450upx;
		// position: a;
		background-image: linear-gradient(to bottom, #0196E0, #FFFFFF);
	}

	.aside {
		width: 93%;
		margin: 0 auto;
		background-color: #FFFFFF;
		border-radius: 16upx;
		padding: 3%;
		margin-top: 20upx;

		.Payment {
			display: flex;
			justify-content: space-between;
		}

		.Payment-content {
			.Payment-one {
				display: flex;
				justify-content: space-between;
				margin-top: 25upx;
			}
		}
	}

	.font-28 {
		font-size: 35upx;
		font-family: PingFangSC, PingFangSC-Semibold;
		font-weight: 600;
		text-align: center;
		color: #2b303d;
		margin-top: 32upx;
	}

	.font-24 {
		font-size: 35upx;
		font-family: PingFangSC, PingFangSC-Regular;
		font-weight: 400;
		text-align: left;
		color: #a7abb6;
	}

	.xg-address {
		width: 100%;
		font-size: 28upx;
		font-family: PingFangSC, PingFangSC-Regular;
		font-weight: 400;
		text-align: left;
		color: #0196e0;
		padding-left: 128upx;
		margin-bottom: 40upx;
	}

	.header-address {
		// height: 200upx;
		width: 100%;
		display: flex;
		margin-top: 40upx;
		padding-left: 24upx;
		padding-right: 24upx;

		// align-items: center;
		.address-icon {
			width: 80upx;
			height: 80upx;
			opacity: 1;
			background: linear-gradient(180deg, #f7a565, #ec6c35);
			border-radius: 50%;
			margin-top: 30upx;
			margin-bottom: 0.48upx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.address-font {
			width: 534upx;
			// height: 80upx;
			opacity: 1;
			margin-left: 28upx;
			font-size: 28upx;
			font-family: PingFangSC, PingFangSC-Semibold;
			font-weight: 600;
			text-align: left;
			color: #2b303d;
			line-height: 40upx;

			.address {
				font-size: 28upx;
				font-family: PingFangSC, PingFangSC-Regular;
				font-weight: 400;
				text-align: left;
				color: #a7abb6;
				margin-top: 16upx;
			}

			// line-height: 40upx;
		}
	}

	.order {
		height: 100%;
		width: 100%;
		background-color: #F4F5F6;
		position: relative;

		.header {
			// width: 686upx;
			// height: 632upx;
			width: 95%;
			opacity: 1;
			background: #ffffff;
			border-radius: 16upx;
			margin: 0 auto;
			margin-top: 24upx;
			display: flex;
			// justify-content: center;
			align-items: center;
			flex-direction: column;

			.icon-address {
				margin-top: 40upx;
			}

			.address-btn {
				width: 307upx;
				height: 88upx;
				opacity: 1;
				border: 2upx solid #0196e0;
				border-radius: 46upx;
				line-height: 88upx;
				text-align: center;
				font-size: 32upx;
				font-family: PingFangSC, PingFangSC-Semibold;
				font-weight: 600;
				text-align: center;
				color: #0196E0;
				margin-top: 64upx;
				margin-bottom: 40upx;
			}
		}

		.nav {
			width: 100%;
			// height: 314upx;
			opacity: 1;
			background: #ffffff;
			border-radius: 16upx;
			margin: 0 auto;
			margin-top: 24upx;

			.nav-shopping {
				width: 100%;
				height: 208upx;
				// border-bottom: 2upx solid #EDEDED;
				display: flex;
				align-items: center;
				padding-left: 24upx;
				padding-right: 24upx;
			}

			.demo-price {
				display: flex;
				font-size: 24upx;
				font-family: PingFangSC, PingFangSC-Semibold;
				font-weight: 600;
				// text-align: left;
				color: #0196e0;
				margin-top: 26upx;
			}

			.gg-font {
				font-size: 24upx;
				font-family: PingFangSC, PingFangSC-Regular;
				font-weight: 400;
				text-align: left;
				color: #a7abb6;
				margin-top: 26upx;
			}
		}

		.bottom-btn {
			// height: 284upx;
			width: 100%;
			text-align: center;
			// line-height: 100upx;
			background-color: #FFFFFF;
			// border-radius: 50upx 50upx 0 0;
			position: fixed;
			bottom: 0;
			padding-right: 32upx;
			padding-bottom: 50upx;
			box-shadow: 0px -8px 16px 0px rgba(0, 0, 0, 0.1);
		}

		.btn {
			width: 240upx;
			height: 88upx;
			line-height: 88upx;
			opacity: 1;
			background: #FFD103;
			border-radius: 44upx;
			// margin: 0 auto;
			margin-top: 12upx;
			font-size: 32upx;
			font-family: PingFangSC, PingFangSC-Semibold;
			font-weight: 600;
			text-align: center;
			color: #ffffff;
		}
	}
</style>
